package com.starsea.book.ui.newpage.weidget.banner.transformer

import android.view.View
import androidx.viewpager.widget.ViewPager.PageTransformer

/**
 * 描述:
 */
abstract class BannerPageTransformer : PageTransformer {
  override fun transformPage(view: View, position: Float) {
    if (position < -1.0f) {
      // [-Infinity,-1)
      // This page is way off-screen to the left.
      handleInvisiblePage(view, position)
    } else if (position <= 0.0f) {
      // [-1,0]
      // Use the default slide transition when moving to the left page
      handleLeftPage(view, position)
    } else if (position <= 1.0f) {
      // (0,1]
      handleRightPage(view, position)
    } else {
      // (1,+Infinity]
      // This page is way off-screen to the right.
      handleInvisiblePage(view, position)
    }
  }

  abstract fun handleInvisiblePage(view: View, position: Float)
  abstract fun handleLeftPage(view: View, position: Float)
  abstract fun handleRightPage(view: View, position: Float)

  companion object {
    fun getPageTransformer(effect: TransitionEffect?): BannerPageTransformer {
      return when (effect) {
        TransitionEffect.Default -> DefaultPageTransformer()
        TransitionEffect.Alpha -> AlphaPageTransformer()
        TransitionEffect.Rotate -> RotatePageTransformer()
        TransitionEffect.Cube -> CubePageTransformer()
        TransitionEffect.Flip -> FlipPageTransformer()
        TransitionEffect.Accordion -> AccordionPageTransformer()
        TransitionEffect.ZoomFade -> ZoomFadePageTransformer()
        TransitionEffect.Fade -> FadePageTransformer()
        TransitionEffect.ZoomCenter -> ZoomCenterPageTransformer()
        TransitionEffect.ZoomStack -> ZoomStackPageTransformer()
        TransitionEffect.Stack -> StackPageTransformer()
        TransitionEffect.Depth -> DepthPageTransformer()
        TransitionEffect.Zoom -> ZoomPageTransformer()
        else -> DefaultPageTransformer()
      }
    }
  }
}